<template>
  <view class="g-content">
   <uni-forms :modelValue="one" ref="form">
      <view>课程名：<span>{{ one['课程名'] }}</span></view>
      <uni-forms-item required label="需求签到课时" name="apl" >
        <uni-easyinput type="number" v-model="num"/>         
      </uni-forms-item>
      <button @click="_setSign">提交</button>
    </uni-forms>
  </view>
</template>

<script>
  import Teacher from '../../../api/Teacher.js';
  export default {
    data(){
      return{
        uid: this.$store.state.token.id,
        one: Object,
        num: ''
      }
    },
    onInit() {
      this.uid = this.$store.state.token.id;
    },
    onLoad(option) {
      this.one = JSON.parse(decodeURIComponent(option.obj));
      this.Test.log('老师-获取该课', this.one);
    },
    methods:{
      async _setSign(){
        uni.showLoading();
        const rm = (await Teacher.setSign(
          this.one['课程号'], 
          this.num
        ));
        this.Test.log('老师-发起签到回执',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('发起失败');
            uni.hideLoading();
            return;
          }
          this.Toast.show('发起成功');
          uni.hideLoading();
          uni.navigateBack();
        }
        this.Toast.show('网络连接失败');
        uni.hideLoading();       
      }
    }
  }
</script>

<style>
</style>
